<template>
  <div>
    <div>&nbsp;</div>
    <div>&nbsp;</div>
    <h1>{{ 'Test Model' }}</h1>

    <div>&nbsp;</div>
    <button @click="onclickLogin"><H1>Login</H1></button>

    <h2>-- session_info.server_version---</h2>
    {{ session_info.server_version }}

    <h2>-- session_info.uid---</h2>
    {{ session_info.uid }}

    <h2>-- session_info.username---</h2>
    {{ session_info.username }}

    <h2>-- session_info.name---</h2>
    {{ session_info.name }}

    <h2>-- context---</h2>
    {{ context }}

    <div>&nbsp;</div>
    <button @click="onclick"><H1>call dataset.call_kw</H1></button>
    <h2>-- modules---</h2>

    {{ offset }}

    <ul>
      <li v-for="mod in modules" :key="mod.id">
        <!-- <div>{{ mod }}</div> -->
        <div>{{ mod.display_name }}</div>
      </li>
    </ul>
    <!-- {{ modules }} -->

    <div>&nbsp;</div>
    <div>&nbsp;</div>
  </div>
</template>

<script>
import api from '@/api_demo/odoorpc_t5'

// const baseURL = 'http://192.168.56.108:8069'
const baseURL = process.env.VUE_APP_BASE_API
const timeout = 50000
api.init({ baseURL, timeout })

export default {
  name: 'TestDataset',
  props: {},
  data() {
    return {
      session_info: {},
      context: {},
      modules: [],
      offset: 0
    }
  },
  computed: {},

  async created() {},
  methods: {
    async onclick() {
      const Model = api.env.model('ir.module.module')

      const result = await Model.search_read({
        domain: [],
        fields: ['name', 'display_name'],
        limit: 8,
        offset: this.offset
      })

      console.log('result:', result)

      this.offset = this.offset + 1

      this.modules = result
    },

    async onclickLogin() {
      console.log('click btn')
      const kwargs = { db: 't1', login: 'admin', password: '123456' }
      const result = await api.web.session.authenticate(kwargs)
      console.log('result:', result)
      this.session_info = result
      this.context = api.web.session.context
    }
  }
}
</script>

<style scoped></style>
